package easy;

import java.util.ArrayList;
import java.util.List;

public class Solution_1002 {

    public List<String> commonChars(String[] words) {
        List<String> list = new ArrayList<>();
        int[][] chars = new int[words.length][26];
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            for (int j = 0; j < word.length(); j++) {
                chars[i][word.charAt(j) - 'a']++;
            }
        }
        for (int i = 0; i < 26; i++) {
            int min = words.length;
            for (int j = 0; j < words.length; j++) {
                if (chars[j][i] < min) {
                    min = chars[j][i];
                }
            }
            for (int k = 0; k < min; k++) {
                list.add(new String(new char[]{(char) (i + 'a')}));
            }
        }
        return list;
    }

    public static void main(String[] args) {
        Solution_1002 model = new Solution_1002();
        System.out.println(model.commonChars(new String[]{"bella","label","roller"}));
        System.out.println(model.commonChars(new String[]{"cool","lock","cook"}));
    }
}
